﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NoteExpress;
using System.Xml.Linq;

namespace neut
{
    public partial class DistributionForm : Form
    {
        public XElement FolderTree
        {
            get;
            set;
        }
        public DistributionForm()
        {
            InitializeComponent();
        }

        void BuildTree(XElement xml,ref TreeNode node)
        {
            foreach (var t in xml.Elements("Folder"))
            {
                var tmp = new TreeNode(t.Attribute("Name").Value);
                node.Nodes.Add(tmp);
                BuildTree(t, ref tmp);
            }
        }

        private void FolderOperation_Load(object sender, EventArgs e)
        {
            var t0 = new TreeNode("分布");
            BuildTree(FolderTree, ref t0);

            treeView1.Nodes.Add(t0);
            treeView1.ExpandAll();
        }


        private void 选择ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var node = treeView1.SelectedNode;
            MessageBox.Show(node.FullPath);
            DialogResult = DialogResult.OK;
        }

        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                TreeNode tn = treeView1.GetNodeAt(e.X, e.Y);
                if (tn != null) treeView1.SelectedNode = tn;
            }   
        }  
    }

}
